import 'package:easy_read_comic/controller/app_controller.dart';
import 'package:easy_read_comic/internal/routes/routes.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:seo_renderer/helpers/renderer_state.dart';
import 'package:seo_renderer/seo_renderer.dart' as SR;

Future<void> main() async {
  await SentryFlutter.init(
    (options) {
      options.dsn =
          'https://fdc4169c47cbe62ae07e869c1f0a2b36@o1365784.ingest.us.sentry.io/4507054420983808';
      options.tracesSampleRate = 1.0;
      options.profilesSampleRate = 1.0;
    },
    appRunner: () async {
      //初始化一次全局状态管理控制器
      await AppController().loadAppDataAndSync();
      AppController().loadConfigAnd();

      EasyRefresh.defaultHeaderBuilder = () => ClassicHeader(
            failedText: "刷新失败",
            dragText: "继续拖拽刷新",
            showMessage: false,
            readyText: "正在请求更新中...",
            processingText: "正在处理中...",
            processedText: "刷新完成",
            noMoreText: "没有更多的数据了",
            armedText: "松开立即刷新",
          );

      EasyRefresh.defaultFooterBuilder = () => ClassicFooter(
            failedText: "加载失败",
            dragText: "继续拖拽加载数据",
            showMessage: false,
            processingText: "正在处理中...",
            processedText: "加载完成",
            readyText: "正在加载中...",
            noMoreText: "没有更多的数据了",
            armedText: "松开立即加载",
          );

      return runApp(
        SR.RobotDetector(
          child: GetMaterialApp(
            initialRoute: "/",
            theme: ThemeData(
              primaryColor: Color(0xFFFF8D65),
            ),
            builder: BotToastInit(),
            navigatorObservers: [BotToastNavigatorObserver(), seoRouteObserver],
            getPages: Routes.Pages,
          ),
        ),
      );
    },
  );
}
